package main

import (
    "fmt"
    "github.com/google/gousb"
)


func main() {
    ctx := gousb.NewContext()
    defer ctx.Close()

    devs, err := ctx.OpenDevices(func(desc *gousb.DeviceDesc) bool {
        return true
    })

    if err != nil {
        fmt.Println("Failed to open devices:", err)
        return
    }

    defer func() {
        for _, dev := range devs {
            dev.Close()
        }
    }()

    for _, dev := range devs {
        fmt.Printf("Device: %s\n", dev.Desc)
      //  for _, config := range dev.Desc.Configs {
    //        fmt.Printf("  Configuration: %s\n", config)
  //          for _, iface := range config.Interfaces {
//                fmt.Printf("    Interface: %s\n", iface)
      //          for _, setting := range iface.AltSettings {
        //            fmt.Printf("      Setting: %s\n", setting)
    //                for _, endpoint := range setting.Endpoints {
  //                      fmt.Printf("        Endpoint: %s\n", endpoint)

                        // 检测每个接口是否插入了设备
 //                       cmd := exec.Command("lsusb", "-t")
 //                       output, err := cmd.Output()
 //                       if err != nil {
 //                           fmt.Println("Failed to run lsusb command:", err)
  //                          continue
//                        }
//                        _usbaddr := fmt.Sprintf("Port %d: Dev ", endpoint.Address)
//                        fmt.Println(_usbaddr)
//                        if strings.Contains(string(output), _usbaddr) {
//                            fmt.Println("          Status: Device connected")
//                        } else {
//                            fmt.Println("          Status: No device connected")
//                        }
//                    }
          //      }
        //    }
       // }
    }
}

